import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:loxen/mode/baidu_map_model.dart';
import 'package:loxen/utils/color.dart';
import 'package:loxen/utils/config.dart';

class LocationListWidget extends StatelessWidget {
  final BDMapData data;
  final bool showDistance;
  final Function(Result) onClick;

  const LocationListWidget({Key key, this.data, this.showDistance, this.onClick}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ListView.builder(
        itemCount: data.result.length,
        itemBuilder: (context, index) {
          return getItem(data.result[index]);
        });
  }

  Widget getItem(Result result) {
    return Padding(
      padding: EdgeInsets.only(left: 30.w, right: 30.w),
      child: InkWell(
        onTap: showDistance
            ? (result.beyond
                ? () {
                    if (onClick != null) {
                      onClick.call(result);
                    }
                  }
                : null)
            : () {
                if (onClick != null) onClick.call(result);
              },
        child: Column(
          children: [
            Container(
              margin: EdgeInsets.only(bottom: 40.h, top: 40.h),
              child: Row(
                children: [
                  Image.asset(
                    showDistance
                        ? (result.beyond ? 'images/location_true.png' : 'images/location_false.png')
                        : 'images/location_true.png',
                    width: 76.w,
                    height: 76.w,
                  ),
                  Expanded(
                    child: Padding(
                      padding: EdgeInsets.only(left: 22.w),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Text(
                            result.name,
                            maxLines: 1,
                            style: TextStyle(
                              fontSize: 28.sp,
                              fontWeight: FontWeight.bold,
                              color: Colours.main_text,
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(top: 10.h),
                            child: Text(
                              result.address,
                              maxLines: 1,
                              style: TextStyle(
                                fontSize: 28.sp,
                                color: Colours.main_text,
                              ),
                            ),
                          )
                        ],
                      ),
                    ),
                  ),
                  showDistance
                      ? (result.beyond
                          ? Constants.empty
                          : Column(
                              children: [
                                Text(
                                  '超出派送范围',
                                  style: TextStyle(
                                    fontSize: 24.sp,
                                    color: Colours.app_main,
                                  ),
                                )
                              ],
                            ))
                      : Constants.empty
                ],
              ),
            ),
            Divider(
              height: 1,
              color: Color(0xffe7e7e7),
            )
          ],
        ),
      ),
    );
  }
}
